/*  -*- mode: c++; coding: utf-8; c-file-style: "stroustrup"; -*-

    Copyright 2008 Asier Aguirre <asier.aguirre@gmail.com>
    This file is part of Intromit.

    Intromit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Intromit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Intromit.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef REFCNT_HH
#define REFCNT_HH
//! \addtogroup util
//@{

#include "util.hh"

//#define REFCNT_DEBUG

class reference_counter
{
    int refcnt;

protected:
    reference_counter();
    virtual ~reference_counter();

public:
    inline void incref()
    {
#       ifdef REFCNT_DEBUG
	DEBUG("%3d++ %p", refcnt, this);
#       endif
	refcnt++;
    }
    reference_counter *decref();

    // getter
    inline int get_refcnt() {return refcnt;}

    // use this function in local or member reference counted objects (to prevent refcnt errors)
    void declared_local_or_member();
};

//@}
#endif

/* Offline metadata attributes:

   @metadata_attrs(
	reference_counter:			# do not select this class (not expose it alone)
						~select
	{
		refcnt:				select
	}
   )
*/
